<?php
require_once("main.php");

$host = "localhost";
$user = "achatell";
$bdd = "achatell";
$passwd  = "**123456";

mysql_connect($host, $user,$passwd) or die("erreur de connexion au serveur");
mysql_select_db($bdd) or die("erreur de connexion a la base de donnees");

$login_query = "SELECT password, token FROM ExtensionUser where login='".getLogin()."'";
$login_result = mysql_query($login_query);
$login_exists = mysql_num_rows($login_result) > 0;

if(!$login_exists){
	$insert_query = "INSERT INTO ExtensionUser (login, password, token) VALUES('"
	. getLogin() . "','" . getPassword() . "','" . getToken() . "');";
	$db_error = !mysql_query($insert_query);
	$result['token'] = getToken();
} else {
	$row = mysql_fetch_row($login_result);
	if(getPassword() == $row[0]){
		$result['token'] = getToken();
	} else {
		$result['error'] = "The password is not correct";
	}
}
echo json_encode($result);
mysql_close();
?>